package com.wxlsoft.excel.core;

import javax.swing.JProgressBar;

public abstract class AbstractProcessor {

	protected JProgressBar progress;
	
	protected void bind(JProgressBar progress) {
		this.progress = progress;
	}
	
	/**
	 * 读取
	 */
	protected abstract void read(JProgressBar progress);
	
	/**
	 * 写出
	 */
	protected abstract void write(JProgressBar progress);

	/**
	 * 准备模板文件
	 */
	protected void copyTmp(JProgressBar progress) {};

	/**
	 * 清理临时文件
	 */
	protected void cleanTmp(JProgressBar progress) {};
	
	/**
	 * 读取并处理数据
	 * @param url
	 */
	public void execute() {
		progress.setValue(20);
		read(progress);
		progress.setValue(progress.getValue() + 10);
		copyTmp(progress);
		progress.setValue(progress.getValue() + 40);
		write(progress);
		cleanTmp(progress);
		progress.setValue(500);
	}
	
}
